#include <winsock2.h>  // This must be included before "windows.h"
#include <windows.h>

#pragma comment(lib, "wpcap.lib")
#pragma comment(lib, "ws2_32.lib")

#define HAVE_REMOTE    // This must be defined before "pcap.h"
#include <pcap.h>

#include "global.h"
#include "headers.h"
#include "lists.h"

#include "xlate.h"
#include "scheduler.h"
#include "open.h"

// MAC for local NICs and gateway
u_char v4LocalMAC[6] = { 0x02, 0x00, 0x4c, 0x4f, 0x4f, 0x50 };
u_char v6LocalMAC[6] = { 0x00, 0x0c, 0x29, 0x22, 0xf7, 0x7b };

u_char v6GatewayMAC[6] = { 0x00, 0x0c, 0x29, 0x99, 0xc1, 0xb6 };
//u_char v6GatewayMAC[6] = { 0x00, 0x0c, 0x29, 0x22, 0xf7, 0x7b };

// "Keep Running" mutexes 
HANDLE  v4RunMutex;
HANDLE  v6RunMutex;

// Handles for network cards
pcap_t *v4Handle;
pcap_t *v6Handle;

// Error buffer for two handles
char v4Errbuf[PCAP_ERRBUF_SIZE];
char v6Errbuf[PCAP_ERRBUF_SIZE];

// pcap_header for two handles
struct pcap_pkthdr *v4Header;
struct pcap_pkthdr *v6Header;

// Receive buffers for two handles
const u_char *v4RecvBuffer;
const u_char *v6RecvBuffer;

// Send buffers for two handles
u_char v4SendBuffer[1600];   // Buffer for v4 device
u_char v6SendBuffer[1600];   // Buffer for v6 device

int main()
{
	// Open pcap devices
	if( open_device() != 0 )
		return -1;

	// Prepare the mapping lists
	init_icmp4to6_list();
	init_icmp6to4_list();
	init_port4to6_list();
	init_port6to4_list();

	// Start threads
	Scheduler();

	return 0;
}